from celery import Celery

# 一、加载django配置环境
import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "luffy_api.settings.dev")

broker = 'redis://127.0.0.1:6379/1'  # 消息中间件 redis
backend = 'redis://127.0.0.1:6379/2'  # 结果存储 redis
app = Celery(__name__, broker=broker, backend=backend,
             include=['celery_task.course_task', 'celery_task.home_task', 'celery_task.user_task'])

# ### 3 定时任务要写在这里
# 时区
app.conf.timezone = 'Asia/Shanghai'
# 是否使用UTC
app.conf.enable_utc = False

# 任务的定时配置
from datetime import timedelta
from celery.schedules import crontab

app.conf.beat_schedule = {
    'update_banner': {
        'task': 'celery_task.home_task.update_banner',
        'schedule': timedelta(seconds=5),
        # 'schedule': crontab(hour=8, day_of_week=1),  # 每周一早八点
        'args': (),
    },
    # 'send_sms': {
    #     'task': 'celery_task.user_task.send_sms',
    #     'schedule': timedelta(seconds=5),
    #     # 'schedule': crontab(hour=8, day_of_week=1),  # 每周一早八点
    #     'args': ('1822344343', 8888),
    # },
    # 'add_course': {
    #     'task': 'celery_task.course_task.add_course',
    #     # 'schedule': crontab(hour=8, day_of_week=1),  # 每周一早八点
    #     'schedule': crontab(hour=18, minute=5),  # 每天11点35，执行
    #     'args': (),
    # }
}
